package com.campus_information_portal.dao;

import com.campus_information_portal.entity.SelfStudy;
import com.campus_information_portal.entity.Studybyoneself;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author
 * @create 2018-06-10 18:03
 **/
public interface SelfStudyDao {

    //根据学生id查询全部
    @Select("select studybyoneself.*,course.course_name " +
            "from studybyoneself,course " +
            "where  studybyoneself.course_id=course.course_id ")
    List<SelfStudy> queryAll();

    //根据学生id查询全部
    @Select("select studybyoneself.*,course.course_name " +
            "from studybyoneself,course " +
            "where studybyoneself.stu_info_id=#{stuInfoId} " +
            "AND studybyoneself.course_id=course.course_id ")
    List<SelfStudy> queryAllByStuId(@Param("stuInfoId")Integer stuInfoId);

    //增加一条
    @Insert("insert into studybyoneself(studybyoneself_id,stu_info_id,studybyoneself_reason," +
            "studybyoneself_flag,course_id) " +
            "values(NULL,#{stuInfoId},null,2,#{courseId})")
    int add(Studybyoneself studybyoneself);

    //修改状态
   @Update("update studybyoneself set studybyoneself_flag=#{studybyoneselfFlag} " +
           "where studybyoneself_id=#{studybyoneselfId}")
   int updateFlag(@Param("studybyoneselfFlag")Integer studybyoneselfFlag,
                   @Param("studybyoneselfId")Integer studybyoneselfId);

   //查询是否申请过
   @Select("select count(course_id) from studybyoneself where stu_info_id=#{stuInfoId} and course_id=#{courseId}")
   int count(@Param("stuInfoId")Integer stuInfoId,@Param("courseId")Integer courseId);

}
